package org.magento.basic;

import java.util.concurrent.TimeUnit;

import org.magenta.data.AdminData;
import org.magenta.data.NewCustomerData;
import org.magenta.utils.configProperties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;


public class basicTestCase {
	
	protected static WebDriver driver;
	
	public AdminData admin = new AdminData("Admin", "test12345");
	
	protected WebDriver getWebDriver() {
		if  (driver == null) {
			driver = new FirefoxDriver();
			driver.manage().timeouts().implicitlyWait(Long.parseLong(configProperties.getProperty("imp.wait")), TimeUnit.SECONDS);
		}
		return driver;
	}
	
	@AfterTest
	public void tearDown() throws Exception {
		driver.quit();
	}
	
	
	//Click on submit button on  login page
	public void submitNewCustomer() {
		driver.findElement(By.cssSelector("button.button.validation-passed")).click();
	}
   // Fill customer data 
	public void fillCreateNewCustomerForm(NewCustomerData newCustomer) {
		// fill create new customer form
		driver.findElement(By.id("firstname")).sendKeys(newCustomer.name);
		driver.findElement(By.id("lastname")).sendKeys(newCustomer.lastname);
		driver.findElement(By.id("email_address")).sendKeys(newCustomer.email);
		driver.findElement(By.id("is_subscribed")).click();
		driver.findElement(By.id("password")).sendKeys(newCustomer.password);
		driver.findElement(By.id("confirmation")).sendKeys(newCustomer.password2);
	}
    // go to create new customer page 
	public void gotoCreateNewCustomerPage() {
		//go to create new customer page.
		driver.get(configProperties.getProperty("url.home"));
		driver.findElement(By.linkText("http://denis.magento.batavi.org/index.php/customer/account/login/")).click();
		driver.findElement(By.cssSelector("div.buttons-set > button.button")).click();
	}

	public void loginToBE() {
		driver.get(configProperties.getProperty("url.home") + "/admin");
	    driver.findElement(By.id("username")).sendKeys("Admin");
	    driver.findElement(By.id("login")).sendKeys("test12345");
	    driver.findElement(By.cssSelector("input.form-button")).click();
	   
	}

	public void logoutFromBE() {
	driver.findElement(By.linkText("Log Out")).click();
	}

	public void closePopupPhoneWorning() {
	//close popup about default cell phone
	driver.findElement(By.cssSelector("a[title=\"close\"] > span")).click();
	}

}
